package JiHe;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Test4_1 {
    public static void main(String[] args) {
        List<String> list = new LinkedList<>();
        List<String> list2 = new LinkedList<>();
        list2.add("a");
        list2.add("b");
        list.add("1");
        list.add("2");
        list.add("3");
        list.add(3,"4");
        list.add(4,"5");
        list.addAll(list2);
        list.addAll(1,list2);
        System.out.println(list);//[1, a, b, 2, 3, 4, 5, a, b]
        System.out.println(list2);//[a, b]
        //查询
        System.out.println(list.get(2));
        //元素首次和最后出现的索引 没有则返回-1
        System.out.println(list.indexOf(3));
        System.out.println(list.lastIndexOf(3));

        list.remove(1);
        list.remove("1");

        list.set(2, "z");

        Iterator<String> it = list.iterator();
        while (it.hasNext()){
            System.out.print(it.next());
        }

        System.out.println("======================================");

        for (String s : list) {
            System.out.print(s);
        }

    }
}
